const md5 = require('md5');
const rp = require('request-promise');
const crypto = require('crypto');
const moment = require('moment/moment.js');
const cid = require('@4a/cid');

module.exports = class extends think.Service {
  async create() {
    try {
      const options = {
        method: 'POST',
        url: 'https://fbm-api.fbmms.cn/oauth2/accessToken',
        body: {
          accessKey: `cnc357njg8o31q49bdv0`,
          secretKey: `StEBgcrgGpeJUL4vLYdhDTl9s6t0FQyF`,
        },
        json: true,
      };

      let sessionData = await rp(options);
      return sessionData.data;
    } catch (e) {
      return null;
    }
  }

  async createVideo() {
    try {
      const options = {
        method: 'POST',
        url: 'https://fbm-api-gw.fbmms.cn/video-interview/api/oauth2/accessToken',
        body: {
          accessKey: `yzhibsuzoeeofmyobp2nhpkmxv`,
          secretKey: `7o83gfjwtc8gedthqrre5juq13`,
          timestamp: moment().unix(),
          requestId: cid(24),
        },
        json: true,
      };

      let sessionData = await rp(options);
      return sessionData.data;
    } catch (e) {
      return null;
    }
  }
};
